﻿@{
    ViewBag.Title = "产品列表";
    Layout = "~/Areas/Shared/_spEdit.cshtml";
   
}
@using Kaiser.Extensions
@model Kaiser.Modules.Cubic.DomainModel.Product.ProductDetail
<script type="text/javascript"   src="@Url.Content("~/Scripts/ueditor/editor_config.js")"></script>
<script type="text/javascript"  src="@Url.Content("~/Scripts/ueditor/editor_all_min.js")"></script>
<script type="text/javascript">
  
    window.UEDITOR_CONFIG.initialFrameHeight = 150;
</script>
<link href="@Url.Content("~/Scripts/Uploadify/3.1/uploadify.css")" rel="stylesheet"  type="text/css" />
<script src="@Url.Content("~/Scripts/Uploadify/3.1/swfobject.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Uploadify/3.1/jquery.uploadify-3.1.min.js")"   type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Plugins/jquery-jtemplates.js")"   type="text/javascript"></script>
<style>
    .w_upload {
        position: relative;
        width: 120px;
        top: -1px;
        float: left;
        padding-right: 4px;
        margin-right: 8px;
    }

    a.item_close:hover {
        text-decoration: none;
        background-position: -100px -200px;
    }

    a.item_close {
        position: absolute;
        background: url(/Themes/images/image_upload.png?2012717) no-repeat;
        background-position: -100px -182px;
        width: 14px;
        height: 14px;
        right: -6px;
        top: -6px;
        text-indent: -9999px;
        overflow: hidden;
    }

    #test {
        position: absolute;
        background: url(/Themes/images/image_upload.png?2012717) no-repeat;
        background-position: -200px -200px;
    }
    .File {
        margin-right: 10px;
    }
    .File a,span{
        text-decoration: none;
        font-family: "宋体";
        font-size: 12px;
    }
  .File .del {
         cursor: pointer;
         margin-left: 8px;
    }
</style>
 
@*<a class="File"  href="/UploadFile/CubicProductFile/2013-08-18/97db5c6b-c68e-4e0a-adba-a21e0178eca1.jpg"><span class="icon icon-pdf"></span><span >示例图片_04.jpg</span><span class="del" onclick="DelAttachFile(this)" AttachId="490">删除</span></a>*@


<form method="post">
    <div class="ftitle">基本信息</div>
    <table>
        <tr>
            <td style="width: 10%;">栏目：
            </td>
            <td>
                
                @Html.TextBoxFor(m => Model.CategoryId, new { @Class = "easyui-combotree", @Style = "width:450px" })
                @Html.HiddenFor(m => Model.CategoryId)
            </td>
        </tr>
        <tr>
            <td>产品编号：
            </td>
            <td>

                @Html.HiddenFor(m => Model.ProductId)
                @Html.TextBoxFor(m => Model.ProductCode, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 552px;" })
            </td>
        </tr>
        <tr>
            <td>中文名称：
            </td>
            <td>

                @Html.TextBoxFor(m => Model.ProductName, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 552px;" })
            </td>
        </tr>

        <tr>
            <td>英文名称：
            </td>
            <td>


                @Html.TextBoxFor(m => Model.ProductEnglishName, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 552px;" })
            </td>
        </tr>
     


    </table>

    <div class="ftitle">产品描述(中文)   </div>


    @Html.TextAreaFor(m => Model.EnglishDehumidifierDescription, new { @Class = "editor", @required = "true" })
    <div class="ftitle">产品描述(Features)   </div>
    @Html.TextAreaFor(m => Model.Features, new { @Class = "editor", @required = "true" })
   
     
    <div class="ftitle">附件列表</div>
    <div id="addFiles" class="attachList">
        @(new HtmlString(Model.Files.ToJson()))
    </div>
    <div id="some_file_queue2" class="some_file_queue">
    </div>

</form>
@*<div>
<div class="w_upload">
    <a class="item_close"  onclick="DelAttach(this)" attachId="{AttachId}" href="javascript:void(0)">删除</a>
    <img width="120" height="88" style="border: 1px solid #95b8e7" src="{SourceUrl}" />
</div>
<div style="float: left;">
    <textarea style="height: 88px"></textarea>
</div>    
</div>*@

<!-- 模板内容 -->
<div id="template" style="display: none">
    <div class="w_upload">
        <a class="item_close"  onclick="DelAttach(this)" attachId="{AttachId}" href="javascript:void(0)">删除</a>
        <img width="120" height="88" style="border: 1px solid #95b8e7" src="{SourceUrl}" />
    </div>
</div>

<script type="text/javascript">
    dlg_Edit_form_submitEvent = function () {
        
        var content = UE.getEditor('EnglishDehumidifierDescription').getContent();
        $("#EnglishDehumidifierDescription").val(encodeURIComponent(content));

        content = UE.getEditor('Features').getContent();
        $("#Features").val(encodeURIComponent(content));
        return true;
    };
    function DelAttach(obj) {
        var attachId = $(obj).attr('AttachId');
        
        $.ajax({
            type: "POST",
            url: '@Url.Action("DelAttachDetail","AttachManage",new {area="Admin"})?ids[0]=' + attachId,
            
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success) {
                    $(obj).closest("div").remove();
                } else {
                    alert(result.msg);
                }
            }
        });
    }
    
    function DelAttachFile(obj) {
        var attachId = $(obj).attr('AttachId');

        $.ajax({
            type: "POST",
            url: '@Url.Action("DelAttachDetail","AttachManage",new {area="Admin"})?ids[0]=' + attachId,

            success: function (result) {
                result = $.parseJSON(result);
                if (result.success) {
                    $(obj).closest(".File").remove();
                } else {
                    alert(result.msg);
                }
            }
        });
    }
    
    $(document).ready(function () {

        $('#CategoryId').combotree({
            url: '@Url.Action("GetCategoryTree", "ProductCategoryManage", new { area = "Cubic", Code = "0" })',
            required: true,
            multiple: false
        });

        $(".editor").each(function () {

            var obj = $(this);

            var editor = new UE.ui.Editor();

            editor.render(obj.attr('id'));
        });

        function getImgElement(attachId, imgUrl) {

            var replaceArr = new Array();
            replaceArr.push({ reg: new RegExp("{SourceUrl}", "gi"), value: imgUrl });
            replaceArr.push({ reg: new RegExp("{AttachId}", "gi"), value: attachId });
            var template = $("#template").html();

            for (var i in replaceArr) {
                var item = replaceArr[i];
                template = template.replace(item.reg, item.value);
            }
           // template.find("");
            return template;
        }

        function BindEvent(imgUrl) {

        }

        $(".attachList").each(function () {

            var o = $(this);
            var oid = o.attr("id");
            var oVal = o.text();
            var arr = $.parseJSON(oVal);
            var photoContern = $("<div id='" + oid + "_photoContern'></div>");
            o.after(photoContern);
            o.uploadify({
                'formData': { "ObjectID": $("#ProductId").val(), "ObjectModule": "CubicProductFile" },
                'swf': '@Url.Content("~/Scripts/Uploadify/3.1/uploadify.swf")',
                'uploader': '@Url.Action("UploadFiles", "AttachManage", new { area = "Admin" })',
                'queueID': 'some_file_queue2',
                "buttonText": "点击添加",
                'buttonCursor': 'arrow',
                'fileTypeExts': '*.pdf',
                onInit: function (instance) {

                    var obj = $("#" + instance.settings.id);
                    if (arr && arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            var file = arr[i];
                            var html = '<span class="File"><a  target="_blank" href="' + file.Url + '"><span class="icon icon-pdf"></span><span>' + file.FileName + '</span></a><a class="del"  AttachId="' + file.Id + '" onclick=DelAttachFile(this)>[删除]</a></span>';
                            photoContern.append(html);
                        }
                    }
                },
                onUploadSuccess: function (a, b) {
                    var result = $.parseJSON(b);
                    if (result.success == false && result.msg && result.msg != "" && result.msg != undefined) {
                        alert(result.msg);
                    } else {
                        var html = '<span class="File"><a  target="_blank" href="' + result.Data.Url + '"><span class="icon icon-pdf"></span><span>' + result.Data.FileName + '</span></a><a class="del"  AttachId="' + result.Data.Id + '" onclick=DelAttachFile(this)>[删除]</a></span>';
                        photoContern.append(html);
                    }
                }
            });
            });

        $(".attachPhotoList").each(function () {

            var o = $(this);
            var oid = o.attr("id");
            var oVal = o.text();
            var arr = $.parseJSON(oVal);
            var photoContern = $("<div id='" + oid + "_photoContern'></div>");  
            o.after(photoContern);
            o.uploadify({
                'formData': { "ObjectID": $("#ProductId").val(), "ObjectModule": "CubicProductPhoto" },
                'swf': '@Url.Content("~/Scripts/Uploadify/3.1/uploadify.swf")',
                'uploader': '@Url.Action("UploadFiles", "AttachManage", new { area = "Admin" })',
                'queueID': 'some_file_queue1',
                "buttonText": "点击添加",
                'buttonCursor': 'arrow',
                'fileTypeExts': '*.gif; *.jpg; *.png',
                onInit: function (instance) {
 
                    var obj = $("#" + instance.settings.id);
                    if (arr && arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            var photo = arr[i];
                            var html = getImgElement(photo.Id, photo.Url);
                            photoContern.append(html);
                        }
                    }
                },
                onUploadSuccess: function (a, b) {
                    var result = $.parseJSON(b);
                    if (result.success== false && result.msg && result.msg != "" && result.msg != undefined) {
                        alert(result.msg);
                    } else {
                        var html = getImgElement(result.Data.Id, result.Data.FilePath);
                        photoContern.append(html);
                    }
                }
            });
        });
    });
</script>


